package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:OrderController
 * Description:
 */
@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户端订单相关接口")
public class OrderController {
    @Autowired
    OrderService orderService;
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submit(OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO =  orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    @GetMapping("historyOrders")
    @ApiOperation("查看历史订单")
    public Result<PageResult> page(int pageNum,int pageSize,int status){
        PageResult pageResult = orderService.pageQuery4User(pageNum,pageSize,status);
        return Result.success(pageResult);
    }
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查看订单详情")
    public Result getById(Long id){
         orderService.getByOrderId(id);
        return Result.success();
    }
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancle(@PathVariable Long id){
        orderService.cancelById(id);
        return Result.success();
    }

    /**
     * 就是吧原订单的数据复制到用户的购物车里
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success();
    }
    @GetMapping("/reminder/{id}")
    @ApiOperation("客户催单")
    public  Result reminder(@PathVariable Long id){
        orderService.reminder(id);
        return  Result.success();
    }
}
